<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon">
  <title>css自适应布局</title>
  <style>
    /* 分隔线样式 */
    .hr {
      width: 100%;
      height: 20px;
      line-height: 20px;
      font-size: 9px;
      background-color: #ccc;
    }

    /* 方法一:浮动 */

    .way_1 #box .left {
      float: left;
      width: 100px;
      height: 100%;
      font-size: 12px;
      background-color: pink;
    }

    .way_1 #box .right {
      height: 100%;
      font-size: 12px;
      background-color: skyblue;
    }

    /* 方法二:flex */
    .way_2 #box {
      display: flex;
    }

    .way_2 #box .left {
      width: 100px;
      height: 100%;
      font-size: 12px;
      background-color: pink;
    }

    .way_2 #box .right {
      flex: 1;
      height: 100%;
      font-size: 12px;
      background-color: skyblue;
    }

    /* 方法三:grid布局 */

    .way_3 #box {
      display: grid;
      overflow: hidden;
      /* 属性定义每一列的列宽 */
      grid-template-columns: 100px 100%;
      /* 属性定义每一列的行高 */
      grid-template-rows: 300px;
    }

    .way_3 #box .left {
      width: 100px;
      height: 100%;
      font-size: 12px;
      background-color: pink;
    }

    .way_3 #box .right {
      height: 100%;
      font-size: 12px;
      background-color: skyblue;
    }

    /* 方法四:利用calc计算宽度 */
    .way_4 #box {
      height: 300px;
    }

    .way_4 #box .left {
      width: 100px;
      height: 100%;
      float: left;
      font-size: 12px;
      background-color: pink;
    }

    .way_4 #box .right {
      width: calc(100% - 100px);
      float: right;
      height: 100%;
      font-size: 12px;
      background-color: skyblue;
    }

    /* 方法五:利用table布局 */
    .way_5 #box {
      display: table;
      width: 100%;
      height: 300px;
    }

    .way_5 #box .left {
      display: table-cell;
      width: 100px;
      height: 100%;
      font-size: 12px;
      background-color: pink;
    }

    .way_5 #box .right {
      display: table-cell;
      height: 100%;
      font-size: 12px;
      background-color: skyblue;
    }
  </style>
</head>

<body>
  <div class="hr">方法一:浮动</div>

  <div class="way_1">
    <div id="box" style="height: 300px;">
      <div class="left">
        左侧固定宽度
      </div>
      <div class="right">
        右侧自适应
      </div>
    </div>
  </div>

  <div class="hr">方法二:flex布局</div>

  <div class="way_2">
    <div id="box" style="height: 300px;">
      <div class="left">
        左侧固定宽度
      </div>
      <div class="right">
        右侧自适应
      </div>
    </div>
  </div>

  <div class="hr">方法三:grid布局</div>

  <div class="way_3">
    <div id="box" style="height: 300px;">
      <div class="left">
        左侧固定宽度
      </div>
      <div class="right">
        右侧自适应
      </div>
    </div>
  </div>

  <div class="hr">方法四:利用calc计算宽度</div>

  <div class="way_4">
    <div id="box" style="height: 300px;">
      <div class="left">
        左侧固定宽度
      </div>
      <div class="right">
        右侧自适应
      </div>
    </div>
  </div>

  <div class="hr">方法五:利用table布局</div>

  <div class="way_5">
    <div id="box" style="height: 300px;">
      <div class="left">
        左侧固定宽度
      </div>
      <div class="right">
        右侧自适应
      </div>
    </div>
  </div>
</body>

</html>